//
//  UIImageView+ILGUIKit.m
//  WangHuo
//
//  Created by zhangtongle on 2017/6/26.
//  Copyright © 2017年 ifeng. All rights reserved.
//

#import "UIImageView+ILGUIKit.h"

@implementation UIImageView (ILGUIKit)
- (void)ilg_setImageWithName:(NSString *)imageName ofType:(NSString *)type {
    NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:type];
    self.image = [UIImage imageWithContentsOfFile:path];
}

- (void)ilg_setFilter:(CGFloat)inputRadius {
    CIImage * ciImage = [[CIImage alloc] initWithImage:self.image];
    
    CIFilter * blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
    
    //将图片输入到滤镜中
    [blurFilter setValue:ciImage forKey:kCIInputImageKey];
    
    //设置模糊程度
    [blurFilter setValue:@(inputRadius) forKey:@"inputRadius"];
    
    //        NSLog(@"查看blurFilter的属性--- %@",blurFilter.attributes);
    
    //将处理之后的图片输出
    CIImage * outCiImage = [blurFilter valueForKey:kCIOutputImageKey];
    
    CIContext * context = [CIContext contextWithOptions:nil];
    
    //获取CGImage句柄
    //        NSLog(@"image rect:%@", NSStringFromCGRect([outCiImage extent]));
    CGImageRef outCGImageRef = [context createCGImage:outCiImage fromRect:[outCiImage extent]];
    
    //获取到最终图片
    UIImage * resultImage = [UIImage imageWithCGImage:outCGImageRef];
    
    self.image = resultImage;
    
    //释放句柄
    CGImageRelease(outCGImageRef);
}
@end
